﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.ObjectModel;
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.Interfaces;
using Wpf.Ui.Mvvm.Contracts;

namespace UiDesktopApp2.ViewModels
{
    public partial class MainWindowViewModel : ObservableObject
    {
        private bool _isInitialized = false;

        private string _applicationTitle = String.Empty;

        public string ApplicationTitle
        {
            get { return _applicationTitle; }
            set
            {
                _applicationTitle = value;
                SetProperty(ref _applicationTitle, value);
            }
        }

        private ObservableCollection<INavigationControl> _navigationItems;

        public ObservableCollection<INavigationControl> NavigationItems
        {
            get { return _navigationItems ?? new ObservableCollection<INavigationControl>(); }
            set
            {
                _navigationItems = value;
                SetProperty(ref _navigationItems, value);
            }
        }

        private ObservableCollection<INavigationControl> _navigationFooter;

        public ObservableCollection<INavigationControl> NavigationFooter
        {
            get { return _navigationFooter ?? new ObservableCollection<INavigationControl>(); }
            set
            {
                _navigationFooter = value;
                SetProperty(ref _navigationFooter, value);
            }
        }

        private ObservableCollection<MenuItem> _trayMenuItems;

        public ObservableCollection<MenuItem> TrayMenuItems
        {
            get { return _trayMenuItems ?? new ObservableCollection<MenuItem>(); }
            set
            {
                _trayMenuItems = value;
                SetProperty(ref _trayMenuItems, value);
            }
        }


        public MainWindowViewModel(INavigationService navigationService)
        {
            if (!_isInitialized)
                InitializeViewModel();
        }

        private void InitializeViewModel()
        {
            ApplicationTitle = "WPF UI - UiDesktopApp2";

            NavigationItems = new ObservableCollection<INavigationControl>
            {
                new NavigationItem()
                {
                    Content = "Home",
                    PageTag = "dashboard",
                    Icon = SymbolRegular.Home24,
                    PageType = typeof(Views.Pages.DashboardPage)
                },
                new NavigationItem()
                {
                    Content = "Data",
                    PageTag = "data",
                    Icon = SymbolRegular.DataHistogram24,
                    PageType = typeof(Views.Pages.DataPage)
                }
            };

            NavigationFooter = new ObservableCollection<INavigationControl>
            {
                new NavigationItem()
                {
                    Content = "Settings",
                    PageTag = "settings",
                    Icon = SymbolRegular.Settings24,
                    PageType = typeof(Views.Pages.SettingsPage)
                }
            };

            TrayMenuItems = new ObservableCollection<MenuItem>
            {
                new MenuItem
                {
                    Header = "Home",
                    Tag = "tray_home"
                }
            };

            _isInitialized = true;
        }
    }
}
